package com.czh.subject.common.utils;

import com.czh.subject.common.constants.UserConstant;
import com.czh.subject.common.context.UserContextHandler;

import java.util.Objects;

/**
 * 用户工具类
 *
 * @author caozaihui
 * @version 1.0
 * @since 2024/9/7 下午 10:29
 */

public class UserUtil {

    /**
     * 获取用户id
     */
    public static String getUserId() {
        Object o = UserContextHandler.get(UserConstant.USER_CONTEXT_ID);
        if (Objects.nonNull(o)) {
            return o.toString();
        }
        return null;
    }

    /**
     * 设置userid
     */
    public static void setUserId(String userId) {
        UserContextHandler.set(UserConstant.USER_CONTEXT_ID, userId);
    }
}
